package org.example.tomcat.servlets;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(name = "MyServlet", urlPatterns = "/my")
//自己的servlet  最终是被上层的 Service方法 调用的 他会智能调用
public class MyServlet extends HttpServlet {

    // 处理 GET 请求
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("do get");
        //实际请求里面 写 分别的 具体逻辑
        response.getOutputStream().write("hello jerry mouse".getBytes());

    }

    // 处理 POST 请求
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("do post");

        response.getOutputStream().write("this is my servlet!".getBytes());

    }



}
